Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int cards, num, count;
char value, j, k, q, t, a, J, K, Q, T, A;
int total = 0;
cout<<"How many cards do you have?"<<endl;
cin>>cards;
count=1;
for (count = 1; count <= cards; count++)
{
if (num=='k'||'K'||'q'||'Q'||'j'||'J'||'t'||'T')
{
num=10;
}
else if (num=='a'||'A')
{
num=11;
}
cout << "Please enter the card value for card " << count <<": "<< endl;
cin >> num;
total=total+num;
}
if (total <=21 && total >= 2)
{
cout << "Total is "<< total << endl;
}
else
cout<< "Bust"<<endl;
return 0;
}
This is just a blackjack program that counts the cards. Something is wrong with my q, k, j, a, I'm trying to give q k j = 10 and ace = 11 or 1. I got the program correctly with normal numbers, but when I start to use q, k, j and a, it starts to bug out :|
Any help would be appreciated, I'm a beginner and this is an exercise, I'm just a bit stuck at the moment
The output should be something like this:
Example 1:
How many cards do you have? 2
Please enter the card values for card 0: a
Please enter the card values for card 1: j
Your score is 21
Example 2:
How many cards do you have? 3
Please enter the card values for card 0: j
Please enter the card values for card 1: k
Please enter the card values for card 2: 3
BUSTED
Edit: Took out the extra things on int, I had a lot of inputs when I was using the switch command, but since I just used a loop instead I took out the card1 card2 etc.